namespace dPet.Infrastructure.EntityFramework.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Hospital",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        Name = c.String(nullable: false, maxLength: 20),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Staff",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        LoginName = c.String(nullable: false, maxLength: 50),
                        EncryptedPassword = c.String(nullable: false, maxLength: 32),
                        Salt = c.String(maxLength: 10),
                        Name = c.String(),
                        Contact = c.String(),
                        LastModified = c.DateTime(nullable: false),
                        StaffRole_Id = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.StaffRole", t => t.StaffRole_Id)
                .Index(t => t.StaffRole_Id);
            
            CreateTable(
                "dbo.StaffRole",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        Name = c.String(nullable: false, maxLength: 20),
                        Privileges = c.Int(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Category",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        Name = c.String(nullable: false, maxLength: 20),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SubCategory",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        Name = c.String(nullable: false, maxLength: 20),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        Category_Id = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Category", t => t.Category_Id)
                .Index(t => t.Category_Id);
            
            CreateTable(
                "dbo.Product",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        Barcode = c.String(nullable: false, maxLength: 50),
                        Name = c.String(nullable: false, maxLength: 50),
                        UnitPrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                        UnitName = c.String(maxLength: 10),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        Category_Id = c.String(maxLength: 32),
                        SubCategory_Id = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Category", t => t.Category_Id)
                .ForeignKey("dbo.SubCategory", t => t.SubCategory_Id)
                .Index(t => t.Category_Id)
                .Index(t => t.SubCategory_Id);
            
            CreateTable(
                "dbo.ProductInventory",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        InventoryNumber = c.String(nullable: false, maxLength: 32),
                        Quantity = c.Int(nullable: false),
                        ExpiryTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        Product_Id = c.String(nullable: false, maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Product", t => t.Product_Id, cascadeDelete: true)
                .Index(t => t.Product_Id);
            
            CreateTable(
                "dbo.InventoryBatch",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        BatchNumber = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        Operator = c.String(maxLength: 50),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.InventoryBatchDetail",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        ProductId = c.String(nullable: false, maxLength: 32),
                        ProductBarcode = c.String(nullable: false, maxLength: 50),
                        ProductName = c.String(nullable: false, maxLength: 50),
                        UnitName = c.String(maxLength: 10),
                        Quantity = c.Int(nullable: false),
                        ExpiryTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        InventoryBatch_Id = c.String(nullable: false, maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.InventoryBatch", t => t.InventoryBatch_Id, cascadeDelete: true)
                .Index(t => t.InventoryBatch_Id);
            
            CreateTable(
                "dbo.SaleOrder",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        MembershipLevel = c.Int(nullable: false),
                        PaymentMethod = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CompleteTime = c.DateTime(nullable: false),
                        Completer = c.String(maxLength: 50),
                        OrderNumber = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        TotalAmount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        CreateTime = c.DateTime(nullable: false),
                        Creator = c.String(maxLength: 50),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.OrderLine",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        ProductBarcode = c.String(nullable: false, maxLength: 50),
                        ProductName = c.String(nullable: false, maxLength: 50),
                        UnitPrice = c.Decimal(nullable: false, precision: 18, scale: 2),
                        UnitName = c.String(maxLength: 10),
                        Quantity = c.Int(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        SaleOrder_Id = c.String(nullable: false, maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.SaleOrder", t => t.SaleOrder_Id, cascadeDelete: true)
                .Index(t => t.SaleOrder_Id);
            
            CreateTable(
                "dbo.InventoryReducingRecord",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        OrderNumber = c.String(nullable: false, maxLength: 32),
                        ProductId = c.String(nullable: false, maxLength: 32),
                        InventoryNumber = c.String(nullable: false, maxLength: 32),
                        ReduceQuantity = c.Int(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.OrderLine", "SaleOrder_Id", "dbo.SaleOrder");
            DropForeignKey("dbo.InventoryBatchDetail", "InventoryBatch_Id", "dbo.InventoryBatch");
            DropForeignKey("dbo.Product", "SubCategory_Id", "dbo.SubCategory");
            DropForeignKey("dbo.ProductInventory", "Product_Id", "dbo.Product");
            DropForeignKey("dbo.Product", "Category_Id", "dbo.Category");
            DropForeignKey("dbo.SubCategory", "Category_Id", "dbo.Category");
            DropForeignKey("dbo.Staff", "StaffRole_Id", "dbo.StaffRole");
            DropIndex("dbo.OrderLine", new[] { "SaleOrder_Id" });
            DropIndex("dbo.InventoryBatchDetail", new[] { "InventoryBatch_Id" });
            DropIndex("dbo.ProductInventory", new[] { "Product_Id" });
            DropIndex("dbo.Product", new[] { "SubCategory_Id" });
            DropIndex("dbo.Product", new[] { "Category_Id" });
            DropIndex("dbo.SubCategory", new[] { "Category_Id" });
            DropIndex("dbo.Staff", new[] { "StaffRole_Id" });
            DropTable("dbo.InventoryReducingRecord");
            DropTable("dbo.OrderLine");
            DropTable("dbo.SaleOrder");
            DropTable("dbo.InventoryBatchDetail");
            DropTable("dbo.InventoryBatch");
            DropTable("dbo.ProductInventory");
            DropTable("dbo.Product");
            DropTable("dbo.SubCategory");
            DropTable("dbo.Category");
            DropTable("dbo.StaffRole");
            DropTable("dbo.Staff");
            DropTable("dbo.Hospital");
        }
    }
}
